package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallOrderCashMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderCash;
import org.linlinjava.litemall.db.domain.LitemallOrderCashExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class LitemallOrderCashService {

    @Resource
    private LitemallOrderCashMapper litemallOrderCashMapper;



    public LitemallOrderCash findById(Integer id) {
        return litemallOrderCashMapper.selectByPrimaryKey(id);
    }



    public int add(LitemallOrderCash record){
        record.setAddTime(LocalDateTime.now());
        return litemallOrderCashMapper.insertSelective(record);
    }

    public int update(LitemallOrderCash record){
        return litemallOrderCashMapper.updateByPrimaryKeySelective(record);
    }

    public int delete(Integer id){
        return litemallOrderCashMapper.logicalDeleteByPrimaryKey(id);
    }


    public List<LitemallOrderCash> queryByOrderId(Integer orderId) {
        LitemallOrderCashExample example = new LitemallOrderCashExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        return litemallOrderCashMapper.selectByExample(example);
    }
    
    /**
     * 查询用户此次的收银记录
     * @param userId
     * @param minTime
     * @return
     */
    public List<LitemallOrderCash> queryAfterTimeByUserId(Integer userId, LocalDateTime minTime) {
    	LitemallOrderCashExample example = new LitemallOrderCashExample();
    	LitemallOrderCashExample.Criteria criteria = example.createCriteria();
    	
    	if(null != userId) {
    		criteria.andAddUserIdEqualTo(userId);
    	}
    	if(null != minTime) {
    		criteria.andAddTimeGreaterThanOrEqualTo(minTime);
    	}
    	criteria.andDeletedEqualTo(false);
    	return litemallOrderCashMapper.selectByExample(example);
    }
}
